<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<title>巡检记录列表</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div class="searchArea">
			<!-- 搜索表单开始 -->
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="FXBR">
						<div class="fieldBox">
							<div class="label">巡检批次</div>
							<div class="field">
								<input type="text" id="routeNo" name="routeNo" class="ui-textbox" ligerui="width: 160" value="">
							</div>
						</div>
						<div class="fieldBox">
				             <div class="label" style="width: 60px;">事业部</div>
				                <div class="field">
				                    <select name="bussDepartment" id="bussDepartment" onchange="searchOrgTreeByOrg(this);" >
				                       <option value="" seleted>请选择</option>
				                       <c:forEach items="${OrgList}" var="orgCd">
				                        	<option value="${orgCd.key}">${orgCd.value}</option>
				                        </c:forEach>
				                    </select>
				             </div>
				        </div>
						<div class="fieldBox">
							<div class="label">省公司</div>
							<div class="field">
								<input name="proCompany" id="proCompany" type="text" value="" placeholder="--请选择--" ltype="combobox">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">巡检状态</div>
							<div class="field">
								<select name="routeState" id="routeState" ligerui="width: 160">
									<option value=" " selected>--请选择--</option>
									<option value="0">未巡检</option>
									<option value="1">巡检中</option>
									<option value="2">巡检结束</option>
								</select>
							</div>
						</div>
					</div>
					
					<div class="clearFix"></div>
					
					<!-- 表单按钮 -->
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round">清空</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
						<span id="addBtn" class="sq-button-round" onclick="batchAddList();">批量生成</span>
		            </div>
		            
				</div>
			</form>
			<!-- 搜索表单结束 -->
		</div>
		<!-- 列表显示块 -->
		<div id="ligergrid1" class="sq-grid"></div>
	</div>
	
	<script type="text/javascript">
		var grid = null;
	    
		//加载
		$(function () {
			initOrgTree();
			$("#searchBar").ligerForm();//初始化表单
		    initGrid();//初始化列表
		    searchBtnEvent();//查询按钮事件
		    clearBtnEvent();//清空按钮事件
		});
	
		//查询参数
		function getSearchParams(){
			var form = new liger.get("searchBar");
			var data = form.getData();
			return data;
		}
		
		//初始化列表
		function initGrid(){
			$("#ligergrid1").ligerGrid({
				url:'<%=path%>/archive/arcRouteMain/initList.do',
				method:'get',
				parms:getSearchParams(),
				columns:[
					{ display: '巡检批次', name: 'routeNo', minWidth: 200, align:'center', enabledSort:true},
					{ display: '事业部', name: 'bussDepartmentNm', minWidth: 150, align:'center', enabledSort:true},
					{ display: '省公司', name: 'proCompanyNm', minWidth: 180, align:'center', enabledSort:true},
					{ display: '巡检状态', name: 'routeState', minWidth: 120, align:'center', enabledSort:true,
						render: function (rowdata, rowindex, value, column) { 
							var h = '未巡检';
							if(rowdata.routeState == '1'){
								h = '巡检中';
							}else if(rowdata.routeState == '2'){
								h = '巡检结束';
							}
							return h;
						}},
					{ display:'操作', isSort:false, minWidth: 140, align:'center', 
						render:function (rowdata, rowindex, value){
							var h="";
				            	h+='<a class="sq-button-hasicon" href="javascript:detailInfo(';
				                h+="'"+rowdata.id+"'";
				                h+=")\">查看</a>";
				                if(rowdata.routeState != '2'){
					                h+='<a class="sq-button-hasicon" href="javascript:updateResult(';
					                h+="'"+rowdata.id+"'";
					                h+=")\">更新结果</a>";
				                }else{
				                	h+='<font class="sq-button-hasicon" color="c9c9c9">更新结果</font>';
				                }
							return h;
						}
					}
				],
				pageSize:10,
				root:'rows',
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'100%',
				heightDiff:-2,
				checkbox:false,//列表是否有选择框
				rownumbers:true//列表是否有行号
			});
			grid = liger.get("ligergrid1");
			//grid.setHeight(100);
			//grid.options.isSingleCheck = true;//列表是否为单选
		}
		
		//清空按钮事件
		function clearBtnEvent(){
			$("#clearBtn").click(function(event) {
				$("#resetBtn").click();  //重置 input-text
				var form = liger.get("searchBar");
				form.setData({  //重置select等特殊表单
					"bussDepartment":" ",
					"routeState":" "
				});
				searchOrgTree2.clear();
			});
		}
		
		//查询按钮事件
		function searchBtnEvent(){
			$("#searchBtn").click(function(event) {
				var form = new liger.get("searchBar");
				var data = form.getData();
				//alert(JSON.stringify(data));
				for (name in data){
					grid.setParm(name,data[name]);
				};
				grid.reload();
			});
		}
		
		//查看巡检详情
		function detailInfo(id) {
			var btnFlag = "no";
			var title ="巡检结果详情";
			Add_navTab("arcRouteDetail"+id, title, '<%=path%>/archive/arcRouteMain/toDetailPage.do?id='+id+'&btnFlag='+btnFlag , function () {
				grid.reload();
			});
		}
		
		//更新巡检详情
		function updateResult(id) {
			var btnFlag = "yes";
			var title ="巡检结果更新";
			Add_navTab("arcRouteUpdate"+id, title, '<%=path%>/archive/arcRouteMain/toDetailPage.do?id='+id+'&btnFlag='+btnFlag , function () {
				grid.reload();
			});
		}
		
		//批量生成巡检记录
		function batchAddList(){
			$.ajax({
				type: 'post',
				dataType: 'json',//该参数涉及到返回值-必须得加
				url: '<%=path%>/archive/arcRouteMain/add.do?',
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
					grid.reload();//刷新列表
				}
			});
		}
		 //初始化查询条件中的下拉树
	    var searchOrgTree2;
	    function initOrgTree(){
	    	 searchOrgTree2 = $("#proCompany").ligerComboBox({
	             selectBoxWidth: 240,
	             selectBoxHeight: 150,
	             treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
	             valueField: 'orgCd',
	             textField: 'orgDispNm',
		    	 tree: {
		             ajaxType: 'get',
		             idFieldName:'orgCd',
		             textFieldName: 'orgDispNm',
		             checkbox: false,
		             parentIcon: "none",
		             childIcon: "none",
		             needCancel : false
		         }
	         });
	    	 var _url = '<%=path%>/warrant/warrantfilemanage/searchBuOrgTree.do';
	    	 AjaxUtils.ajaxGet(_url, {}, function(msg){
	    		if(msg.success == 1){
	  				searchOrgTree2.treeManager.setData(msg.data);
	  				searchOrgTree2.clear();
	  			}else{
	  				UIUtils.alertError(msg.info);
	  			}
	    	 },false);
	    }
		 //通过查询条件获取Tree数据
	    function searchOrgTreeByOrg (obj) {
	        var _url = '<%=path%>/warrant/warrantfilemanage/searchBuOrgTree.do';
	        var params = {};
	        params.cstMgrOrgCd=obj.value;
	    	AjaxUtils.ajaxGet(_url, params, function(msg){
	    		if(msg.success == 1){
	  				searchOrgTree2.treeManager.setData(msg.data);
	  				searchOrgTree2.clear();
	  			}else{
	  				UIUtils.alertError(msg.info);
	  			}
	    	 },false);
	    }
	</script>
</body>
</html>